package org.batatasframework.expression;

import org.batatasframework.values.DelegateValueGetter;
import org.batatasframework.values.NullValueGetter;
import org.batatasframework.values.StringValueGetter;
import org.batatasframework.values.ValueGetter;

/**
 * 指令的一个参数项，
 * 如：
 * name = -f my -m 100
 * 
 * 解析后
 * {@link #commandName} = -f
 * {@link #commandValue} = 100
 * 
 * @author jackson
 *
 */
public class CommandExpressionArgument extends DelegateValueGetter{
	
	/** 指令参数名称 */
	private final String commandName;
	/** 指令参数值 */
	private final ValueGetter commandValue;
	private final ValueGetter defaultValue;
	
	CommandExpressionArgument(){
		this(null, NullValueGetter.nullValue(), NullValueGetter.nullValue());
	}
	
	public CommandExpressionArgument(String commandName, String value){
		this(commandName, StringValueGetter.valueOf(value), NullValueGetter.nullValue());
	}
	
	public CommandExpressionArgument(String commandName, ValueGetter commandValue, ValueGetter defaultValue){
		this.commandName = commandName;
		this.commandValue = commandValue;
		this.defaultValue = defaultValue;
	}
	
//	@Override
//	protected ValueGetter getValue() {
//		return commandValue;
//	}
	
	/**
	 * 值为空或不可用的状态
	 * @return
	 */
	public boolean disabled(){
		return commandValue == NullValueGetter.nullValue();
	}
	
	public String getName() {
		return commandName;
	}
	
	public ValueGetter getDefaultValue() {
		return defaultValue;
	}

	@Override
	public ValueGetter getValue(){
		return commandValue;
	}
}
